/*
var apple = {
	color: "green"
}

function Start() {
alert(apple.color);
}
*/
var secCounter = 60;

function degree(number, deg) {
	var result = number;
	if (deg == 0) return 1;
	for(var i = 1; i < deg; ++i) 
		result *= number;
	return result;
}

function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

function max(a, b) {
	if (a > b) return a;
		else return b;
}

function define_rank(num) {
	if (num < 10) return 1;
		else if (num > 9 && num < 100) return 2;
		else if (num > 99 && num < 1000) return 3;
}

function take_operation(num1, num2) {
	switch (operation) {
		case "Sum":
			return num1 + num2;
			break;
		case "Dif":
			return num1 - num2;
			break;
		case "Multiply":
			return num1*num2;
			break;
		case "Del":
			return num1/num2;
			break;
	}
}

function take_operation_sign() {
	switch (operation) {
		case "Sum":
			return "+";
			break;
		case "Dif":
			return "-";
			break;
		case "Multiply":
			return "*";
			break;
		case "Del":
			return "/";
			break;
	}
}

function TaskRepeat() {
	if (repetitions == left_nums.length)
		repetitions = 0;
		
	randomnumber1 = left_nums[repetitions];
	randomnumber2 = right_nums[repetitions];
	operation = operations[repetitions];
	operation_sign = take_operation_sign();
	++repetitions;
	
	right_ans = take_operation(randomnumber1, randomnumber2);
	temp_ans_rank = define_rank(right_ans);
}

var arith_class = {
	operation: "no_operation",
	operation_sign: "no_sign",
	operation_func: "no_operation_func",
	ans: -1,
	left_rank: -1,
	right_rank: -1,
	ans_rank: -1,
	temp_ans_rank: -1,
	right_ans: -1,
	right_ans_rank: -1,
	right_score: 0,
	wrong_score: 0,
	randomnumber1: 0,
	randomnumber2: 0,
	isGameOver: 0,
	left_nums: [],
	right_nums: [],
	operations: [],
	repetitions: 0,
	isTaskUniq: function(number1, number2) {
		for (i = 0; i < left_nums.length; i++)
			if ((number1 == left_nums[i] && number2 == right_nums[i] &&
				operation == operations[i])||(number2 == left_nums[i] &&
				number1 == right_nums[i] && operation == operations[i]) == 1) {
				return 0;
			}
		return 1;
	}
}

function timer() {
	var timer_watch = document.getElementById("timer1");
	
	timer_watch.firstChild.nodeValue = secCounter.toString();
	if (secCounter !== 0) {		
		secCounter = secCounter - 1;		
		window.setTimeout("timer()", 1000);
	} else {
		var d = document.getElementById("txt1");
		d.firstChild.nodeValue = "Your score is " + arith_class.right_score.toString();
		arith_class.isGameOver = 1;
	}
}

function newSum11() {
		arith_class.randomnumber1 = getRandomInt(1, 9);
		arith_class.randomnumber2 = getRandomInt(1,9);
		arith_class.right_ans = arith_class.randomnumber1 + arith_class.randomnumber2;
		if (arith_class.right_ans < 10) arith_class.temp_ans_rank = 1;
			else arith_class.temp_ans_rank = 2;
}

function Start() {
	arith_class.operation_sign = "+";
	arith_class.operation = "Sum";
	arith_class.operation_func = newSum11;
	arith_class.left_rank = 1;
	arith_class.right_rank = 1;
	arith_class.ans_rank = -1;
	//document.documentElement.addEventListener("keydown", keyHandler, false);
	timer();
}
